package leetcode_2401_2500;

public class LeeCode_2409 {
    public static void main(String[] args) {
//        System.out.println(countDaysTogether("09-01", "10-19", "06-19", "10-20"));
        System.out.println(countDaysTogether("10-01","10-31","11-01","12-31"));
    }
    private static int countDaysTogether(String arriveAlice, String leaveAlice, String arriveBob, String leaveBob) {
        int[] table = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] sum = new int[13];
        for (int i = 1; i <= table.length; i++) {
            sum[i] = table[i - 1] + sum[i - 1];
        }
        String[] la = leaveAlice.split("-");
        int lan = sum[Integer.parseInt(la[0])] + Integer.parseInt(la[1]);
        String[] aa = arriveAlice.split("-");
        int aan = sum[Integer.parseInt(aa[0])] + Integer.parseInt(aa[1]);
        String[] lb = leaveBob.split("-");
        int lbn = sum[Integer.parseInt(lb[0])] + Integer.parseInt(lb[1]);
        String[] ab = arriveBob.split("-");
        int abn = sum[Integer.parseInt(ab[0])] + Integer.parseInt(ab[1]);
        int ans = Math.min(lbn, lan) - Math.max(aan, abn);
        if (ans == 0)
            return 0;
        return Math.max(ans + 1, 0);
    }
}
